﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace PcArduinoControl
{
	public class AnalogInputPin :
		IAnalogPin, IPin
	{
		// TODO: Switch to sbyte where we need to so we can actually send negative values without making the user use unchecked and stuff.

		internal event AnalogInputStreamChangedHandler StreamModeChanged;
		
		public byte Number { get; protected set; }
		public PinType Type { get { return PinType.Input; } }
		public byte AnalogValue { get; internal set; }

		public InputStreamMode StreamMode
		{
			get
			{
				return mStreamMode;
			}
			set
			{
				mStreamMode = value;
				OnStreamModeChanged();
			}
		}

		InputStreamMode mStreamMode;

		public AnalogInputPin(byte pin)
		{
			Number = pin;
			mStreamMode = InputStreamMode.Never;
		}

		void OnStreamModeChanged()
		{
			var valueChanged = StreamModeChanged;
			if (valueChanged != null)
				valueChanged.Invoke(Number, mStreamMode);
		}
	}
}
